/**
 * Created by root on 17-7-27.
 */
const schedule = require('node-schedule');
const logger = require('./config/log4js');
const xiciTask = require('./task/xiciHttpProxyTask');
const verifyHttpTask = require('./task/verifyHttpTask');
const data5uHttpTask = require('./task/data5uHttpProxyTask');
const kuaidailiHttpTask = require('./task/kuaidailiHttpProxyTask');
const liuliuipHttpProxyTask = require('./task/66ipHttpProxyTask');
const mysql = require('mysql');
const ipnet = require('xz-ipnet')();

logger.access.info("Start!");

/**
 * 全局初始化 ip地址库
 */
global.ipnet = ipnet;

/**
 * 全局错误捕获防止 崩掉
 */
process.on('uncaughtException', function (err) {
    logger.error.info('Caught exception: ' + err);
});

var dbPool;

// 初始化db
exports.getDB = function () {

    if (dbPool != null) return dbPool;
    dbPool = mysql.createPool({
        host     : '123.56.221.27',
        user     : 'root',
        password : '745764370HExu..',
        database : 'reptile'
    });
    return dbPool;
};

/**
 * 检测代理是佛可用
 */
// verifyHttpTask.start();

/**
 * 开启xici代理采集
 */
xiciTask.start();

/**
 * 开启5u代理采集
 */
data5uHttpTask.start();

/**
 * 开启快代理采集
 */
kuaidailiHttpTask.start();

/**
 * 开启66代理数据采集
 */
liuliuipHttpProxyTask.start();